<template>
  <div class="pet_item_container">
    <div class="img_box">
      <img class="img1"
           :src="imgUrl" />

    </div>
    <div class="detail_box">

      <div class="pet_type">
        <b class="type1">{{title}} </b>
        <b class="type2">{{petFrom.petName}}</b>
      </div>

      <div class="addr">
        <b class="type1">{{typeName}} </b>
        <b class="type2">{{petFrom.petTypeName}}</b>
      </div>

      <div class="addr">
        <b class="type1">地址: </b>
        <b class="type2">{{petFrom.addr}}</b>
      </div>

      <div class="addr">
        <b class="type1">联系人: </b>
        <b class="type2">{{petFrom.contactName}}</b>
      </div>

      <div class="addr">
        <b class="type1">联系方式: </b>
        <b class="type2">{{petFrom.phoneNumber}}</b>
      </div>

      <div class="addr">
        <b class="type1">发布时间: </b>
        <b class="type2">{{petFrom.startTime}}</b>
      </div>

      <hr />

      <div class="addr">
        <b class="type1">描述: </b>
      </div>
      <div class="detail">
        <b class="type3">{{petFrom.detail}}</b>
      </div>

      <div class="bottom">

      </div>
    </div>

    <el-button size="small"
               @click="contactOnline()"
               class="btn_contact">在线咨询</el-button>

  </div>
</template>
<script>
import { getCategoryImg } from "../../api/http.js";
export default {
  props: {
    toPet: {}
  },
  created () {
    console.log(this.petFrom)
    this.getCategoryImg(this.petFrom.petImg)
    this.gettitleName()
    // 调用时间格式转换
    this.petFrom.startTime = this.getDateByStartDate(this.petFrom.startTime)

  },
  data () {
    return {
      petFrom: this.toPet,
      imgUrl: '../../assets/img/kinds (2).jpg',
      title: '宠物姓名:',
      typeName: '品种：'

    }
  },
  methods: {
    // 获取宠物图片
    async getCategoryImg (petImg) {
      console.log("petImgL:" + petImg)
      const { data: res } = await getCategoryImg(petImg);
      this.imgUrl = window.URL.createObjectURL(res);
    },
    //  在线联系
    contactOnline () {
      // console.log(this.petFrom)
      console.log("消息接收者：" + this.petFrom.userId)
      // 将消息接收者id传递给父组件
      this.$emit('toUserId', this.petFrom.userId);
      this.$emit('toContactName', this.petFrom.contactName);
    },
    gettitleName () {
      let routerPath = this.$route.path
      console.log(routerPath)
      if (routerPath == '/loveAdopt')
        this.title = '标题:'
      else if (routerPath == '/pair')
        this.title = "标题:"
      else if (routerPath == '/lostFind') {
        this.title = "标题:"
        this.typeName = "丢失位置:"
      }

    },
    // 时间格式转换
    getDateByStartDate (date) {
      let dt = new Date(date)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
    },
  }

}
</script>
<style lang="less" scoped>
.pet_item_container {
  display: flex;
  margin-left: 100px;
  margin-right: 100px;
  margin-top: 40px;
  background: url("../../assets/img/b2.jpg") no-repeat;
  background-size: 100% 100%;
  padding-right: 20px;
  min-height: 400px;
  max-height: 500px;
  padding-top: 20px;
  position: relative;
  .img_box {
    //  display: flex;
    //  background-color: brown;
    text-align: center;
    width: 47%;
    padding-top: 20px;
    padding-bottom: 20px;
    .img1 {
      width: auto;
      height: auto;
      max-width: 500px;
      max-height: 320px;
      margin: 0 auto;
      box-shadow: 0 0 50px 30px #ffffff inset;
    }
    .btn {
      background-color: violet;
      color: white;
      position: relative;
      left: 100%;
      bottom: 0;
      margin-bottom: 0;
      // transform: translate(-20%, -20%);
    }
  }
  .detail_box {
    //  background-color: brown;
    margin-left: 4%;
    width: 49%;
    height: auto;
    p {
      margin: 0;
    }
    .pet_type {
      // display: table-cell;
      // ertical-align: bottom;
      text-align: center;
    }
    //  分割线
    hr {
      margin-top: 10px;
      margin-bottom: 10px;
      display: block;
      clear: both;
      width: 100%;
      height: 1px;
      border: 0;
      background: #757272;
    }
    .addr {
      margin-top: 10px;
      text-align: center;
    }
    .detail {
    }
    .bottom {
      width: 100%;
      height: auto;
      background-color: cadetblue;
    }
  }
  .btn_contact {
    background-color: violet;
    color: white;
    position: absolute;
    bottom: 0;
    right: 0;
    transform: translate(-50%, -50%);
  }
}
.type1 {
  color: violet;
  padding-top: 7px;
  font-size: 16px;
  font-weight: bold;
}
.type2 {
  color: rgb(255, 255, 255);
  padding-top: 7px;
  font-size: 16px;
  font-weight: normal;
}
.type3 {
  color: rgb(252, 252, 252);
  padding-top: 7px;
  font-size: 14px;
  font-weight: normal;
  font: inherit;
}
</style>